package com.xijia.wuyouwallet.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.xijia.wuyouwallet.MyApp;
import com.xijia.wuyouwallet.R;
import com.xijia.wuyouwallet.bean.RefundData;
import com.xijia.wuyouwallet.utils.StringUtils;

import java.util.List;

/**
 * Created by Administrator on 2017/12/1 0001.
 */

public class CreditcardRefundAdapter extends BaseAdapter {

    private List<RefundData> list;
    private Context context;
    private reFundCallBack callBack;


    public CreditcardRefundAdapter(List<RefundData> list,Context context,reFundCallBack callBack){
        this.list = list;
        this.context = context;
        this.callBack = callBack;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        ViewHolder holder = null;
        if (view==null){
            holder = new ViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.item_refund,null);
            holder.itemRefund_bankName = (TextView) view.findViewById(R.id.itemRefund_bankName);
            holder.itemRefund_userName = (TextView) view.findViewById(R.id.itemRefund_userName);
            holder.itemRefund_bankNum = (TextView) view.findViewById(R.id.itemRefund_bankNum);
            holder.itemRefund_time = (TextView) view.findViewById(R.id.itemRefund_time);
            holder.itemRefund_refundMoney = (TextView) view.findViewById(R.id.itemRefund_refundMoney);
            holder.itemRefund_availableMoney = (TextView) view.findViewById(R.id.itemRefund_availableMoney);
            holder.itemRefund_bankIcon = (ImageView) view.findViewById(R.id.itemRefund_bankIcon);
            holder.itemRefund_delete = (TextView) view.findViewById(R.id.itemRefund_delete);
            holder.itemRefund_upDate = (TextView) view.findViewById(R.id.itemRefund_upDate);
            view.setTag(holder);
        }else {
            holder = (ViewHolder) view.getTag();
        }
        holder.itemRefund_bankName.setText(list.get(i).getCard_name());
        holder.itemRefund_userName.setText(MyApp.userData.getData().getNick_name());
        holder.itemRefund_bankNum.setText("**** **** **** "+StringUtils.hintBankFourNum(list.get(i).getCard_num()));
        //holder.itemRefund_time.setText(list.get(i).getRepay_end_time());
        holder.itemRefund_refundMoney.setText(list.get(i).getRepay_pay_money());
        holder.itemRefund_availableMoney.setText(list.get(i).getRepay_have_money());
        //PicassoUtils.getinstance().loadImageViewHolder(context,true,list.get(i).getCard_img(),R.mipmap.uc);
        holder.itemRefund_time.setText("("+list.get(i).getRepay_end_time()+")");
        Picasso.with(context).load(list.get(i).getCard_img()).into(holder.itemRefund_bankIcon);
        holder.itemRefund_upDate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                callBack.delect(i,"1");
            }
        });
        holder.itemRefund_delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                callBack.delect(i,"2");
            }
        });
        return view;
    }

    private class ViewHolder{
        TextView itemRefund_bankName,itemRefund_userName,itemRefund_bankNum,
                itemRefund_time,itemRefund_refundMoney,itemRefund_availableMoney,
                itemRefund_delete,itemRefund_upDate;
        ImageView itemRefund_bankIcon;
    }

    public interface reFundCallBack{
        void delect(int postion,String type);
    }

}
